﻿using System;
using System.Collections.ObjectModel;
using System.Drawing.Printing;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

namespace TAProject.UI
{
    public partial class FormReportPlaceHolder : FormTemplate
    {
        private readonly Form _parentForm;
        private readonly Collection<ReportDataSource> _reportDataSourceCollection;
        private readonly ReportParameterCollection _reportParameterCollection;
        private readonly string _reportEmbededResource;

        public FormReportPlaceHolder()
        {
            InitializeComponent();
        }

        public FormReportPlaceHolder(Form parentForm, Collection<ReportDataSource> reportDataSourceCollection, 
            ReportParameterCollection reportParameterCollection, string reportEmbededResource)
            : base(parentForm)
        {
            InitializeComponent();

            _parentForm = parentForm;
            _reportDataSourceCollection = reportDataSourceCollection;
            _reportParameterCollection = reportParameterCollection;
            _reportEmbededResource = reportEmbededResource;

            _parentForm.Enabled = false;

            reportViewer.LocalReport.ReportEmbeddedResource = _reportEmbededResource;
            foreach (var dataSourcre in _reportDataSourceCollection)
            {
                reportViewer.LocalReport.DataSources.Add(dataSourcre);
            }
            reportViewer.LocalReport.SetParameters(_reportParameterCollection);
            reportViewer.RefreshReport();

            reportViewer.PrinterSettings.DefaultPageSettings.Landscape = true;
            reportViewer.PrinterSettings.DefaultPageSettings.Margins.Bottom = 10;
            reportViewer.PrinterSettings.DefaultPageSettings.Margins.Top = 20;
            reportViewer.PrinterSettings.DefaultPageSettings.Margins.Bottom = 5;
            reportViewer.PrinterSettings.DefaultPageSettings.Margins.Bottom = 5;
        }

        private void FormReportPlaceHolder_Load(object sender, EventArgs e)
        {
            
        }

        private void ButtonCloseClick(object sender, EventArgs e)
        {
            _parentForm.Enabled = true;
            Close();
        }
    }
}
